<admintpl file="header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:U('NewsColumn/index')}">栏目列表</a></li>
        <li><a href="#" onclick="addColumnType('{$column_id}');">添加栏目</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form" action="{:U('NewsColumn/index')}" method="post">
        <table class="table table-hover table-bordered">
            <thead>
            <tr>
                <th>序号</th>
                <th>栏目类型</th>
                <th>权重</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="vo" key="keys">
                <tr>
                    <td>{$keys+1}</td>
                    <td><input type="text" name="type_name" id="type_name_{$vo.type_id}" value="{$vo.name}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_name_{$vo.type_id}" href='javascript:void(0);' onclick="update_weight('{$vo.type_id}','name')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_name" id="old_name_{$vo.type_id}" value="{$vo.name}"></td>
                    <td><input type="text" name="weight" id="weight{$vo.type_id}" value="{$vo.weight}" disabled="disabled" size="4"  class="input_edit">
                        <a id="edit_weight_{$vo.type_id}" href='javascript:void(0);' onclick="update_weight('{$vo.type_id}','weight')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_weight" id="old_weight_{$vo.type_id}" value="{$vo.weight}">
                    </td>
                    <td><a href='{:U("Admin/NewsColumn/del",array("type_id"=>$vo["type_id"]))}' class="js-ajax-dialog-btn"
                           data-msg="确定要删除此地区吗？">删除</a></td>
                </tr>
            </foreach>
            </tbody>
        </table>
    </form>
    <div class="pagination">{$page}</div>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    function update_weight(type_id,type){

        if(type == 'weight'){
            edit_column = $("#edit_weight_"+type_id).html();
            column_befor = $("#old_weight_"+type_id).val();//原权重值
            column  = $("#weight"+type_id).val(); //现权重值
            now_input_type = $("#weight" + type_id); //权重 ID
            now_edit_type  = $("#edit_weight_" + type_id);  //修改 按钮ID
        }else if(type == 'name'){
            edit_column = $("#edit_name_"+type_id).html();
            column_befor = $("#old_name_"+type_id).val();//原栏目名称值
            column  = $("#type_name_"+type_id).val(); //现栏目名称值
            now_input_type = $("#type_name_" + type_id); //栏目名称 ID
            now_edit_type  = $("#edit_name_" + type_id);  //修改 按钮ID
        }

        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                if(type == "name"){
                    $.ajax({
                        type:"post",
                        async:false,
                        url:"{:U('Admin/Movement/filter_words')}",
                        data:'name='+column,
                        dataType:"text",
                        success:function(data){
                            if(data){
                                if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
                                    flag= true;
                                    return true;
                                }else{
                                    flag= false;
                                    return false;
                                }
                            }else{
                                flag = true;
                                return true;
                            }
                        }
                    });
                    if(flag == false){
                        return false;
                    }
                }
                $.post("{:U('NewsColumn/editColumnType')}", {type: type, type_id: type_id, val: column},
                        function (result) {
                            if (result == 1) {
                                now_input_type.attr("disabled", "disabled");
                                now_edit_type.html("修改");
                                location.reload()
                            }else{
                                alert("异常!")
                            }
                        }
                );
            }
        }
    }

    function addColumnType(column_id){
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '添加栏目类型',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['1000px', '500px'],
            content: "<?php echo U('Admin/NewsColumn/addType')?>"+'&column_id='+column_id,
            end: function(){
                location.reload();
            }
        });
    }
//    function refresh_news(news_id){
//        $.post("<?php echo U('Admin/NewsManage/refreshNews')?>",{news_id:news_id}, function(result){
//            if(result == '1'){
//                var msg = '刷新成功';
//            }else{
//                var msg = '刷新失败';
//            }
//
//            alert(msg);
//            window.location.reload();
//        });
//    }
//    $(document).ready(function () {
//
//        $('input[name="query_form_btn"]').click(function () {
//            $('#query_form').attr('action', $(this).attr('data-action'));
//            $('#query_form').submit();
//        });
//        $("#category").val("{$formParam.categoryId}");
//
//
//    });

</script>
</body>
</html>